package com.jxs.android.ges.util;

import java.util.Calendar;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;
import android.widget.Toast;

import com.jxs.android.weiget.BuAlertDailog;

public class Utils {
	private static Toast sToast;

	public static void toast(Context context, String info, boolean isLong) {
		if (sToast == null) {
			if (isLong) {
				sToast = Toast.makeText(context, info, Toast.LENGTH_LONG);
			} else {
				sToast = Toast.makeText(context, info, Toast.LENGTH_SHORT);
			}
		}
		sToast.setText(info);
		sToast.show();
	}

	public static void debug(String tag, String info) {
		Log.d(tag, info);
	}

	public static boolean isNetAvailable(Context context) {
		boolean netSataus = false;
		ConnectivityManager cwjManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

		cwjManager.getActiveNetworkInfo();

		if (cwjManager.getActiveNetworkInfo() != null) {
			netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
		}
		return netSataus;
	}

	public static void setNetWork(Context context, BuAlertDailog.AlertOkAndCancelListener alertOkAndCancelListener) {
		BuAlertDailog.builder(context, "没有可用的网络", "是否对网络进行设置？", alertOkAndCancelListener).show();
	}

	public static int compareCurDate(int year, int month, int day) {
		Calendar c = Calendar.getInstance();
		int calendarYear = c.get(Calendar.YEAR);
		int calendarMonth = c.get(Calendar.MONTH);
		int calendarDay = c.get(Calendar.DAY_OF_MONTH);
		int deltaYear = year - calendarYear;
		if (deltaYear != 0)
			return deltaYear;
		int deltaMon = month - calendarMonth;
		if (deltaMon != 0)
			return deltaMon;
		return day - calendarDay;
	}

}
